<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" autoFlush="true"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ page import="java.util.*"%>

<%@ page
	import="cn.myapps.core.validate.repository.action.ValidateRepositoryHelper"%>
<ww:bean name="cn.myapps.core.dynaform.form.action.FormHelper" id="fh">
	<ww:param name="moduleid" value="#parameters.moduleid" />
</ww:bean>
<html><o:MultiLanguage>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href='<ww:url value="/resource/css/main.css" />' type="text/css">
<ww:bean name="cn.myapps.core.dynaform.view.action.ViewHelper"
	id="viewHelper">
	<ww:param name="moduleid" value="#parameters.moduleid" />
</ww:bean>
<link href="../css/dialog.css" rel="stylesheet" type="text/css" />
<script src='<ww:url value="/dwr/engine.js"/>'></script>
<script src='<ww:url value="/dwr/util.js"/>'></script>
<script src='<ww:url value="/dwr/interface/FormHelper.js"/>'></script>
<script src='<ww:url value="/dwr/interface/Sequence.js"/>'></script>
<script src='<ww:url value="/script/util.js"/>'></script>
<script src='<ww:url value="/dwr/interface/ActivityUtil.js"/>'></script>
<script language="JavaScript" src="dialog.js"></script>
<script language="JavaScript" src="script.js"></script>
<script language="JavaScript" src="sequence.js"></script>
<link href="../css/dialog.css" rel="stylesheet" type="text/css" />
<script src="common/fck_dialog_common.js" type="text/javascript"></script>

<SCRIPT language="JavaScript">
var sAction = URLParams['action'] ;
var sTitle = "{*[Insert]*}";
var oControl;
var oSeletion;
var sRangeType;
var contextPath = '<%=request.getContextPath()%>';

var dialog	= window.parent ;
var oEditor = dialog.InnerDialogLoaded() ;

// Gets the document DOM
var oDOM = oEditor.FCK.EditorDocument ;

var oActiveEl = dialog.Selection.GetSelectedElement() ;

function ev_init(fn1,fn2,fn3,fn4,fn5) {
	var instance = '<%= request.getParameter("application")%>';
	var mdlid = '<%= request.getParameter("moduleid")%>';
	var def1 = document.getElementsByName(fn1)[0].value;
	var def2 =  document.getElementsByName(fn2)[0].value;
	var def3 =  document.getElementsByName(fn3)[0].value;
	var def4 =  document.getElementsByName(fn4)[0].value;
	var def5 =  document.getElementsByName(fn5)[0].value;
	var afterscript = document.getElementById("afterscriptid");
	
	if (!document.getElementsByName(fn1)[0].value){def1 = oActiveEl && oActiveEl.actType ? oActiveEl.actType : ''}
	if (!document.getElementsByName(fn2)[0].value){def2 = oActiveEl && oActiveEl.onActionView ? oActiveEl.onActionView : ''}
	if (!document.getElementsByName(fn3)[0].value){def3 = oActiveEl && oActiveEl.onActionForm ? oActiveEl.onActionForm : ''}
	if (!document.getElementsByName(fn4)[0].value){def4 = oActiveEl && oActiveEl.onActionFlow ? oActiveEl.onActionFlow : ''}
	if (!document.getElementsByName(fn5)[0].value){def5 = oActiveEl && oActiveEl.onActionPrint ? oActiveEl.onActionPrint : ''}
	else if (document.getElementsByName(fn1)[0].value=='none'){
		def2 = 'none';
		def3 = 'none';
		def4 = 'none';
		def5 = 'none'
	}
	
	oview_tr.style.display = "none";
	oflow_tr.style.display = "none";	
	oform_tr.style.display = "none";
	oprint_tr.style.display = "none";
	ofilename_tr.style.display = "none";
	approve_tr.style.display = "none";
	afterscript.style.display = "inline";
	oexcelconfig_tr.style.display = "none";
	
	var func = new Function("ev_init('"+fn1+"','"+fn2+"','"+fn3+"','"+fn4+"','"+fn5+"')");
	
	document.getElementsByName(fn1)[0].onchange = func;
	
	ActivityUtil.createFormTypeExceptJUMP(fn1,def1,32,function(str) {var func=eval(str);func.call()}); // 创建表单选项
	
	ActivityUtil.createOnActionView(fn2,def1,mdlid,def2,instance,function(str) {var func=eval(str);func.call()});
	ActivityUtil.createOnActionForm(fn3,def1,mdlid,def3,instance,function(str) {var func=eval(str);func.call()});
	ActivityUtil.crateOnActionFlow(fn4,def1,mdlid,def4,function(str) {var func=eval(str);func.call()});
	ActivityUtil.createOnActionPrint(fn5,def1,mdlid,def5,function(str) {var func=eval(str);func.call()});

	switch (def1.toString()) {
		case '1':
			oview_tr.style.display = "inline";
			break;
		case '5':
			oflow_tr.style.display = "inline";
			break;
		case '6':
			afterscript.style.display = "none";
			break;
		case '2':
			oform_tr.style.display = "inline";
			break;
		case '18':
			oform_tr.style.display = "inline";
			break;
		case '20':
			approve_tr.style.display = "inline";
			break;
		case '26':
			ofilename_tr.style.display = "inline";
			break;
		case '27':
			oexcelconfig_tr.style.display = "inline";
			break;
		case '30':
			oprint_tr.style.display = "inline";
			break;
		default:
			break;
		}
}

// 选项卡点击事件
function cardClick(cardID){
	var obj;
	for (var i=1;i<5;i++){
		obj=document.all("card"+i);
		obj.style.backgroundColor="#3A6EA5";
		obj.style.color="#FFFFFF";
	}
	obj=document.all("card"+cardID);
	obj.style.backgroundColor="#FFFFFF";
	obj.style.color="#3A6EA5";
	
	for (var i=1;i<5;i++){
		obj=document.all("content"+i);
		obj.style.display="none";
	}
	obj=document.all("content"+cardID);
	obj.style.display="";
	resize();
}

//document.write("<title>{*[ButtonField]*}{*[Property]*}（" + sTitle + "）</title>");

//初始值
function InitDocument(){
	var editMode;
	oEditor.FCKLanguageManager.TranslatePage(document);
	ev_init('content.type','_onActionViewid','_onActionFormid','_onActionFlowid','_onActionPrintid');
	
	if ( oActiveEl && (oActiveEl.tagName == 'INPUT'))
	{
		if(oActiveEl.name!=null){
			temp.name.value = HTMLDencode(oActiveEl.name);
		}
		// 脚本部分
		if(oActiveEl.refreshOnChanged!=null){
			temp.refreshOnChanged.checked = oActiveEl.refreshOnChanged == "true";
		}else{
			temp.refreshOnChanged.checked = false;
		}
			
		if(oActiveEl.calculateOnRefresh!=null){
			temp.calculateOnRefresh.checked = oActiveEl.calculateOnRefresh == "true";
		}else{
			temp.calculateOnRefresh.checked = false;
		}
		
		if(oActiveEl.hiddenScript!=null){
			temp.hiddenScript.value = HTMLDencode(oActiveEl.hiddenScript);
		}

			
		if(oActiveEl.hiddenValue!=null){
			temp.hiddenValue.value = HTMLDencode(oActiveEl.hiddenValue);
		}

		if(oActiveEl.hiddenPrintScript!=null){
			temp.hiddenPrintScript.value = HTMLDencode(oActiveEl.hiddenPrintScript);
		}

		if(oActiveEl.printHiddenValue!=null){
			temp.printHiddenValue.value = HTMLDencode(oActiveEl.printHiddenValue);
		}

		if(oActiveEl.readonlyScript!=null){
			temp.readonlyScript.value = HTMLDencode(oActiveEl.readonlyScript);	
		}

		if(oActiveEl.fileNameScript!=null){
			temp.fileNameScript.value = HTMLDencode(oActiveEl.fileNameScript);
		}

		if(oActiveEl.stateToShow!=null){
			temp.stateToShow.value = HTMLDencode(oActiveEl.stateToShow);
		}

		if(oActiveEl.approveLimit!=null){
			temp.approveLimit.value = HTMLDencode(oActiveEl.approveLimit);
		}

		if(oActiveEl.beforeActionScript!=null){
			temp.beforeActionScript.value = HTMLDencode(oActiveEl.beforeActionScript);
		}

		if(oActiveEl.afterActionScript!=null){
			temp.afterActionScript.value = HTMLDencode(oActiveEl.afterActionScript);
		}

		if(oActiveEl.mobile!=null){
			temp.mobile.checked = oActiveEl.mobile == "true";
		}else{
			temp.mobile.checked = false;
		}
			for(i=0;i<temp.onActionFlow.options.length;i++){
				if(temp.onActionFlow.options[i].value==GetAttribute( oActiveEl, 'onActionFlow' )){
				    temp.onActionFlow.selectedIndex = i;
					break;
				}
			} 
			for(i=0;i<temp.actType.options.length;i++){
				if(oActiveEl.actType==temp.actType.options[i].value){
				    temp.actType.selectedIndex = i;
					break;
				} 
			}
			for(i=0;i<temp.onActionView.options.length;i++){
				if(GetAttribute(oActiveEl, 'onActionView')==temp.onActionView.options[i].value){
				    temp.onActionView.selectedIndex = i;
					break;
				} 
			}
			for(i=0;i<temp.onActionForm.options.length;i++){
				if(GetAttribute(oActiveEl, 'onActionForm')==temp.onActionForm.options[i].value){
				    temp.onActionForm.selectedIndex = i;
					break;
				}
			}

			for(i=0;i<temp.onActionPrint.options.length;i++){
				if(GetAttribute(oActiveEl, 'onActionPrint')==temp.onActionForm.options[i].value){
				    temp.onActionPrint.selectedIndex = i;
					break;
				}
			}
			
			for(i=0;i<temp.impmappingconfigid.options.length;i++){
				if(oActiveEl.impmappingconfigid==temp.impmappingconfigid.options[i].value){
				    temp.impmappingconfigid.selectedIndex = i;
					break;
				} 
			}
	}
	else
		oActiveEl = null ;
	dialog.SetOkButton( true ) ;
	dialog.SetAutoSize( true ) ;
	SelectField( 'name' ) ;
	window.top.toThisHelpPage("application_module_form_info_advance_button");
}

function selectedOne(Obj, value, callback) {
	if (Obj != null) {
		for (i = 0; i < Obj.options.length; ++i)
			if (Obj.options[i].value == value) {
				Obj.selectedIndex = i;
				if (callback) {
					callback(Obj);
				}
				break;
			}
	}
}

function getSelectedValueById(id){
	var actType = document.getElementById(id);
	var temp;
	if(actType!=null){
		temp= actType.options[actType.selectedIndex].value;
	}
	return temp;
}

function Ok()
{
	if(ev_check()){
	oEditor.FCKUndo.SaveUndoStep() ;
	var className="cn.myapps.core.dynaform.form.ejb.ButtonField";
	var id=getFieldId();	
	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {
									classname: className,
									id: id,
									type:"button",
									value:temp.name.value,
									name: GetE('name').value,
									hiddenScript:HTMLEncode(GetE('hiddenScript').value),
									hiddenValue:HTMLEncode(GetE('hiddenValue').value),
									hiddenPrintScript:HTMLEncode(GetE('hiddenPrintScript').value),
									printHiddenValue:HTMLEncode(GetE('printHiddenValue').value),
									readonlyScript:HTMLEncode(GetE('readonlyScript').value),
									refreshOnChanged:HTMLEncode(temp.refreshOnChanged.checked+""),
									calculateOnRefresh:HTMLEncode(temp.calculateOnRefresh.checked+""),
									mobile: HTMLEncode(temp.mobile.checked+""),
									fileNameScript:HTMLEncode(temp.fileNameScript.value),
								    stateToShow:temp.stateToShow.value,
								    approveLimit:temp.approveLimit.value,
								    beforeActionScript:HTMLEncode(temp.beforeActionScript.value),
								    afterActionScript:HTMLEncode(temp.afterActionScript.value),
								    actType:HTMLEncode(getSelectedValue(temp.actType)),
								   	onActionView:HTMLEncode(getSelectedValue(temp.onActionView)),
								   	onActionForm:HTMLEncode(getSelectedValue(temp.onActionForm)),
								   	onActionFlow:HTMLEncode(getSelectedValue(temp.onActionFlow)),
								    onActionPrint:HTMLEncode(GetE('onActionPrint').value),
								   	impmappingconfigid:HTMLEncode(getSelectedValue(temp.impmappingconfigid))
									} 
								   ) ;	
	//alert("temp._onActionViewid.options[temp._onActionViewid.selectedIndex].value-->"+temp._onActionViewid.options[temp._onActionViewid.selectedIndex].value);
	return true ;
	}
}

//检查内容是否完成正确
function ev_check(){
   if(temp.name.value==''){
 	 alert("{*[page.name.notexist]*}");
	  return false;
   }else if(HTMLEncode(getSelectedValue(temp.actType))==0){
	   alert("{*[please.choose.type]*}");
      return false;
   }
   return !checkStartChar(temp.name.value);
}

function checkStartChar(value){
	return IsDigit(value,"{*[page.name.startingit]*}");
}

function IsDigit(s,msg){
	var text = s.substring(0,1);
	var patrn=/^[0-9]{1}$/; 
	if (patrn.exec(text)){
		alert(msg);
		return true;
	}
	return false;
}

function selectField(actionName, field){
	var applicationid = '<%= request.getParameter("application")%>';
	var url = contextPath + '/core/dynaform/activity/'+ actionName +'.action?application=' + applicationid;
	//alert("url-->"+url);
	if (field != '' && field != null) {
		url = url + '&field=' + field;
	}
	//alert("url-->"+url);
	var oField = document.getElementsByName('content.' + field)[0];
	var rtn = window.showModalDialog(url, oField, "dialogHeight:400px; dialogWidth:300px; status:no; scroll:no;");
	if(rtn){
		oField.value = rtn;
	} else if (rtn == '') {
		oField.value = rtn;
	}
}
</script>

</HEAD>

<BODY onload="InitDocument()">

<ww:form name="temp" theme="simple">
		<table border="0" cellpadding="3" cellspacing="0" width="520px">
			<tr align=center>
				<td class="card" onclick="cardClick(1)" id="card1">{*[Basic]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(2)" id="card2">{*[Hidden_Script]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(3)" id="card3">{*[Hidden_Print_Script]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(4)" id="card4">{*[ReadOnly_Script]*}</td>
				<td width=2></td>
			</tr>
			<tr style="overflow:auto;height:215px;width:100%">
				<td valign="middle" colspan="12" bgcolor="#ffffff" align="center"
					width="100%">
				<!-- content1 -->
				<div style="overflow-y:auto;height:250px;">
				<table border=1 cellpadding=3 cellspacing=1 class="content" id="content1" width="520px">
					<tr>
						<td class="commFont commLabel">{*[Name]*}:</td>
						<td align="left"><ww:textfield id="name" name="content.name" cssStyle="width:100%;"/></td>
					</tr>
					
					<tr>
						<td align="center" colspan="2">
							<input type=checkbox name="refreshOnChanged" value="true">{*[Refresh]*}&nbsp;
							<input type=checkbox name="calculateOnRefresh" value="true">{*[Recalculate]*}&nbsp;
							<input type="checkbox" name="mobile" value="true" checked />{*[Mobile]*}&nbsp;
						</td>
					</tr>
					
					<tr>
					    <td class="commFont commLabel">{*[Type]*}:</td>
						<td align="left"><ww:select id="actType" cssStyle="width:100%" emptyOption="true" name="content.type" list="{}" /></td>
					</tr>
			
					<tr id="oview_tr">
						<td class="commFont commLabel">{*[OnActionView]*}:</td>
						<td align="left"><ww:select id="onActionView" cssStyle="width:100%;" emptyOption="true" name="_onActionViewid" list="{}" /></td>
					</tr>
			
					<tr id="oform_tr">
						<td class="commFont commLabel">{*[OnActionForm]*}</td>
						<td align="left"><ww:select id="onActionForm" cssStyle="width:100%;" emptyOption="true"  name="_onActionFormid" list="{}" /></td>
					</tr>
			
					<tr id="oflow_tr">
						<td class="commFont commLabel">{*[OnActionFlow]*}</td>
						<td align="left"><ww:select id="onActionFlow" cssStyle="width:100%;" emptyOption="true" name="_onActionFlowid" list="{}" /></td>
					</tr>
			
					<tr id="ofilename_tr">
						<td class="commFont commLabel">{*[FileNameScript]*}</td>
						<td><ww:textarea id="fileNameScript" cssClass="input-cmd" cssStyle="width:92%;" name="content.fileNameScript" cols="50" rows="3" />
						<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('content.fileNameScript','{*[Script]*}{*[Editor]*}','{*[FileNameScript]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
						</td>
					</tr>
			
					<tr id="oexcelconfig_tr">
						<ww:bean name="cn.myapps.core.dynaform.dts.excelimport.config.action.ImpHelper" id="hepler" />
						<td class="commFont commLabel">{*[Import]*}{*[MappingConfig]*}:</td>
						<td><ww:select id="impmappingconfigid" name="_impmappingconfigid" cssStyle="width:350px;" list="#hepler.get_allMappingConfig(#parameters.application)" listKey="id" listValue="name" theme="simple" emptyOption="true" /></td>
					</tr>
				
					<tr>
						<td class="commFont commLabel">{*[StateToShow]*}:</td>
						<td><ww:textfield id="stateToShow" readonly="true" cssStyle="100%" cssClass="input-cmd" name="content.stateToShow" />
							
						<button class="button-image" onClick="selectField('statelist','stateToShow');">
							<img src="<ww:url value="/resource/image/search.gif"/>">
						</button>
						</td>
					</tr>
					
					<tr id="approve_tr">
						<td class="commFont commLabel">{*[Approve]*}{*[To]*}:</td>
						<td><ww:textfield id="approveLimit" cssStyle="width:100%" readonly="true" cssClass="input-cmd" name="content.approveLimit" />
							
						<button class="button-image" onClick="selectField('statelist','approveLimit');">
							<img src="<ww:url value="/resource/image/search.gif"/>">
						</button>
						</td>
					</tr>
					
					<tr id="oprint_tr">
						<td class="commFont commLabel">{*[OnActionPrint]*}</td>
						<td align="left"><ww:select id="onActionPrint" cssStyle="width:350px;" emptyOption="true" name="_onActionPrintid" list="{}" /></td>
					</tr>
			
					<tr>
				  		<td class="commFont commLabel">{*[BeforeActionScript]*}:</td>
						<td><ww:textarea cssClass="input-cmd" cssStyle="width:92%;" name="beforeActionScript" cols="50" rows="3" />
						<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('beforeActionScript','{*[Script]*}{*[Editor]*}','{*[BeforeActionScript]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
						</td>
					</tr>
					
					<tr id ="afterscriptid">
				  		<td class="commFont commLabel">{*[AfterActionScript]*}:</td>
						<td><ww:textarea cssClass="input-cmd" cssStyle="width:92%;" name="afterActionScript" cols="50" rows="3" />
						<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('afterActionScript','{*[Script]*}{*[Editor]*}','{*[AfterActionScript]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
						</td>
					</tr>
				</table>
				
				<table border="1" cellpadding="3" cellspacing="1" class="content" width="100%" id="content2">
					<tr>
						<td><textarea name="hiddenScript" style="width:96%" rows="10"></textarea>
						<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('hiddenScript','{*[Script]*}{*[Editor]*}','{*[Hidden_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
						</td>
					</tr>
					<tr>
						<td>{*[hiddenValue]*}：<input type="text" name="hiddenValue" /></td>
					</tr>
				</table>
				<table border="1" cellpadding="3" cellspacing="1" class="content" width="100%"
					id="content3">
					<tr>
						<td><textarea name="hiddenPrintScript" style="width:96%" rows="10"></textarea>
						<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('hiddenPrintScript','{*[Script]*}{*[Editor]*}','{*[Hidden_Print_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
						</td>
					</tr>
					<tr>
						<td>{*[Print]*}{*[hiddenValue]*}：<input  type="text" name="printHiddenValue" /></td>
					</tr>
				</table>
				<table border="1" cellpadding="3" cellspacing="1" class="content" width="95%"
					id="content4">
					<tr>
						<td><textarea name="readonlyScript" style="width:96%" rows="10"></textarea>
						<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('readonlyScript','{*[Script]*}{*[Editor]*}','{*[ReadOnly_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
						</td>
					</tr>
				</table>
				</div>
				</td>
			</tr>
		</table>
</ww:form>

<script language=javascript>
cardClick(1);
</script>

</BODY>
</o:MultiLanguage>
</HTML>
